unit cef3api;

{$MODE objfpc}{$H+}
{.$MODE Delphi}

{$I cef.inc}

interface

uses
    Dynlibs,
    sysutils,
    ctypes,
    cef3types;

type
    {$i cef_pointers.inc}

    tfn_cef_simple_proc = procedure; cdecl;

    {$i cef_base_capi.inc}                      //+
    {$i cef_command_line_capi.inc}              //+
    {$i cef_values_capi.inc}                    //+
    {$i cef_browser_process_handler_capi.inc}   //+
    {$i cef_dom_capi.inc}                       //+
    {$i cef_request_capi.inc}                   //+
    {$i cef_stream_capi.inc}                    //+
    {$i cef_string_visitor_capi.inc}            //+
    {$i cef_frame_capi.inc}                     //+
    {$i cef_process_message_capi.inc}           //+
    {$i cef_load_handler_capi.inc}              //+
    {$i cef_task_capi.inc}                      //*
    {$i cef_v8_capi.inc}                        //*
    {$i cef_render_process_handler_capi.inc}    //+
    {$i cef_resource_bundle_handler_capi.inc}   //*
    {$i cef_callback_capi.inc}                  //+
    {$i cef_cookie_capi.inc}                    //+
    {$i cef_response_capi.inc}                  //*
    {$i cef_request_context_handler_capi.inc}   //N
    {$i cef_request_context_capi.inc}           //N
    {$i cef_drag_data_capi.inc}                 //*
    {$i cef_browser_capi.inc}                   //+
    {$i cef_resource_handler_capi.inc}          //*
    {$i cef_scheme_capi.inc}                    //*
    {$i cef_app_capi.inc}                       //*
    {$i cef_menu_model_capi.inc}                //*
    {$i cef_context_menu_handler_capi.inc}      //*
    {$i cef_dialog_handler_capi.inc}            //*
    {$i cef_display_handler_capi.inc}           //+
    {$i cef_download_item_capi.inc}             //*
    {$i cef_download_handler_capi.inc}          //*
    {$i cef_drag_handler_capi.inc}              //*
    {$i cef_focus_handler_capi.inc}             //*
    {$i cef_geolocation_handler_capi.inc}       //*
    {$i cef_geolocation_capi.inc}               //*
    {$i cef_jsdialog_handler_capi.inc}          //*
    {$i cef_keyboard_handler_capi.inc}          //*
    {$i cef_life_span_handler_capi.inc}         //*
    {$i cef_render_handler_capi.inc}            //*
    {$i cef_web_plugin_capi.inc}                //*
    {$i cef_request_handler_capi.inc}           //+
    {$i cef_client_capi.inc}                    //*
    {$i cef_auth_callback_capi.inc}             //N
    {$i cef_trace_capi.inc}                     //+? Deleted record
    {$i cef_urlrequest_capi.inc}                //+
    {$i cef_xml_reader_capi.inc}                //*
    {$i cef_zip_reader_capi.inc}                //*
    {$i cef_origin_whitelist_capi.inc}
    {$i cef_path_util_capi.inc}
    {$i cef_process_util_capi.inc}
    {$i cef_url_capi.inc}
    {$i cef_version.inc}

    {$ifdef cef_stable}
    {$endif cef_stable}
    {$ifdef cef_trunk}
    {$i cef_print_settings_capi.inc}
    {$i cef_print_handler_capi.inc}
    {$endif cef_trunk}

    // internal
    {$i cef_string_types.inc}
    {$i cef_string_list.inc}
    {$i cef_string_map.inc}
    {$i cef_string_multimap.inc}

var
    {$i cef_api_functions.inc}

{ ***  cef_time.h  *** }
    // Converts cef_time_t to/from time_t. Returns true (1) on success and false (0)
    // on failure.
    //cef_time_to_timet: function(const cef_time: PCefTime; time: PTimet): Integer; cdecl;
    //cef_time_from_timet: function(time: TTimet; cef_time: PCefTime): Integer; cdecl;

    // Converts cef_time_t to/from a double which is the number of seconds since
    // epoch (Jan 1, 1970). Webkit uses this format to represent time. A value of 0
    // means "not initialized". Returns true (1) on success and false (0) on
    // failure.
    //cef_time_to_doublet: function(const cef_time: PCefTime; time : PDouble): Integer; cdecl;
    //cef_time_from_doublet: function(time: Double; cef_time: PCefTime): Integer; cdecl;

    // Retrieve the current system time.
    cef_time_now: function(cef_time: PCefTime): Integer; cdecl;

    // Retrieve the delta in milliseconds between two time values.
    //cef_time_delta: function(const cef_time_1, cef_time_2: PCefTime; delta: P long long): Integer; cdecl;

procedure CefLoadLibrary;
procedure CefCloseLibrary;

implementation

uses Math;

const
    CefLibrary: string = 'libcef';
var
    LibHandle: TLibHandle = 0;


// Convenience macros for copying values.
function cef_string_wide_copy(const src: PWideChar; src_len: csize_t;  output: PCefStringWide): Integer;
begin
    Result := cef_string_wide_set(src, src_len, output, ord(True))
end;

function cef_string_utf8_copy(const src: PAnsiChar; src_len: csize_t; output: PCefStringUtf8): Integer;
begin
    Result := cef_string_utf8_set(src, src_len, output, ord(True))
end;

function cef_string_utf16_copy(const src: PChar16; src_len: csize_t; output: PCefStringUtf16): Integer; cdecl;
begin
    Result := cef_string_utf16_set(src, src_len, output, ord(True))
end;

function cef_string_copy(const src: PCefChar; src_len: csize_t; output: PCefString): Integer; cdecl;
begin
    Result := cef_string_set(src, src_len, output, ord(True));
end;
{ ***                     *** }

procedure CefLoadLibrary;
var
    fle: string = ''; // not empty if some function(s) not found

    function GetProcAddrN(const AName: string; const ARaise: Boolean = false): Pointer;
    begin
        Result := GetProcAddress(LibHandle, PChar(AName));
        if not Assigned(Result) then
        begin
        if ARaise then
            raise Exception.CreateFmt('Error loading API function: %s', [AName])
        else
            fle := fle + LineEnding + AName;
        end;
    end;
begin
    {$IFDEF DEBUG}
    Debugln('CefLoadLibrary');
    {$ENDIF}

    if LibHandle = 0 then
    begin
        Set8087CW(Get8087CW or $3F); // deactivate FPU exception
        SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);

        LibHandle := SafeLoadLibrary(CefLibrary);

        If LibHandle = 0 then
            raise Exception.Create(GetLoadErrorStr);

        cef_build_revision  := tfn_cef_build_revision(
            GetProcAddrN('cef_build_revision'));
        cef_version_info    := tfn_cef_version_info(
            GetProcAddrN('cef_version_info'));
        cef_api_hash        := tfn_cef_api_hash(
            GetProcAddrN('cef_api_hash'));

        cef_execute_process         := tfn_cef_execute_process(
            GetProcAddrN('cef_execute_process'));
        cef_initialize              := tfn_cef_initialize(
            GetProcAddrN('cef_initialize'));
        cef_shutdown                := tfn_cef_shutdown(
            GetProcAddrN('cef_shutdown'));
        cef_do_message_loop_work    := tfn_cef_do_message_loop_work(
            GetProcAddrN('cef_do_message_loop_work'));
        cef_run_message_loop        := tfn_cef_run_message_loop(
            GetProcAddrN('cef_run_message_loop'));
        cef_quit_message_loop       := tfn_cef_quit_message_loop(
            GetProcAddrN('cef_quit_message_loop'));
        cef_set_osmodal_loop        := tfn_cef_set_osmodal_loop(
            GetProcAddrN('cef_set_osmodal_loop'));

        cef_browser_host_create_browser := tfn_cef_browser_host_create_browser(
            GetProcAddrN('cef_browser_host_create_browser'));
        cef_browser_host_create_browser_sync := tfn_cef_browser_host_create_browser_sync(
            GetProcAddrN('cef_browser_host_create_browser_sync'));

        cef_command_line_create := tfn_cef_command_line_create(
            GetProcAddrN('cef_command_line_create'));
        cef_command_line_get_global := tfn_cef_command_line_get_global(
            GetProcAddrN('cef_command_line_get_global'));

        cef_cookie_manager_get_global_manager := tfn_cef_cookie_manager_get_global_manager(
            GetProcAddrN('cef_cookie_manager_get_global_manager'));
        cef_cookie_manager_create_manager := tfn_cef_cookie_manager_create_manager(
            GetProcAddrN('cef_cookie_manager_create_manager'));

        cef_get_geolocation := tfn_cef_get_geolocation(
            GetProcAddrN('cef_get_geolocation'));

        cef_add_cross_origin_whitelist_entry := tfn_cef_add_cross_origin_whitelist_entry(
            GetProcAddrN('cef_add_cross_origin_whitelist_entry'));
        cef_remove_cross_origin_whitelist_entry := tfn_cef_remove_cross_origin_whitelist_entry(
            GetProcAddrN('cef_remove_cross_origin_whitelist_entry'));
        cef_clear_cross_origin_whitelist := tfn_cef_clear_cross_origin_whitelist(
            GetProcAddrN('cef_clear_cross_origin_whitelist'));

        cef_get_path := tfn_cef_get_path(
            GetProcAddrN('cef_get_path'));

        cef_process_message_create := tfn_cef_process_message_create(
            GetProcAddrN('cef_process_message_create'));

        cef_launch_process := tfn_cef_launch_process(
            GetProcAddrN('cef_launch_process'));

        cef_request_create := tfn_cef_request_create(
            GetProcAddrN('cef_request_create'));
        cef_post_data_create := tfn_cef_post_data_create(
            GetProcAddrN('cef_post_data_create'));
        cef_post_data_element_create := tfn_cef_post_data_element_create(
            GetProcAddrN('cef_post_data_element_create'));

        cef_request_context_get_global_context := tfn_cef_request_context_get_global_context(
            GetProcAddrN('cef_request_context_get_global_context'));
        cef_request_context_create_context := tfn_cef_request_context_create_context(
            GetProcAddrN('cef_request_context_create_context'));

        cef_response_create := tfn_cef_response_create(
            GetProcAddrN('cef_response_create'));

        cef_register_scheme_handler_factory := tfn_cef_register_scheme_handler_factory(
            GetProcAddrN('cef_register_scheme_handler_factory'));
        cef_clear_scheme_handler_factories := tfn_cef_clear_scheme_handler_factories(
            GetProcAddrN('cef_clear_scheme_handler_factories'));

        cef_stream_reader_create_for_file := tfn_cef_stream_reader_create_for_file(
            GetProcAddrN('cef_stream_reader_create_for_file'));
        cef_stream_reader_create_for_data := tfn_cef_stream_reader_create_for_data(
            GetProcAddrN('cef_stream_reader_create_for_data'));
        cef_stream_reader_create_for_handler := tfn_cef_stream_reader_create_for_handler(
            GetProcAddrN('cef_stream_reader_create_for_handler'));
        cef_stream_writer_create_for_file := tfn_cef_stream_writer_create_for_file(
            GetProcAddrN('cef_stream_writer_create_for_file'));
        cef_stream_writer_create_for_handler := tfn_cef_stream_writer_create_for_handler(
            GetProcAddrN('cef_stream_writer_create_for_handler'));

        cef_task_runner_get_for_current_thread := tfn_cef_task_runner_get_for_current_thread(
            GetProcAddrN('cef_task_runner_get_for_current_thread'));
        cef_task_runner_get_for_thread := tfn_cef_task_runner_get_for_thread(
            GetProcAddrN('cef_task_runner_get_for_thread'));
        cef_currently_on := tfn_cef_currently_on(
            GetProcAddrN('cef_currently_on'));
        cef_post_task := tfn_cef_post_task(
            GetProcAddrN('cef_post_task'));
        cef_post_delayed_task := tfn_cef_post_delayed_task(
            GetProcAddrN('cef_post_delayed_task'));

        cef_begin_tracing := tfn_cef_begin_tracing(
            GetProcAddrN('cef_begin_tracing'));
        cef_end_tracing := tfn_cef_end_tracing(
            GetProcAddrN('cef_end_tracing'));
        cef_now_from_system_trace_time := tfn_cef_now_from_system_trace_time(
            GetProcAddrN('cef_now_from_system_trace_time'));

        cef_parse_url := tfn_cef_parse_url(
            GetProcAddrN('cef_parse_url'));
        cef_create_url := tfn_cef_create_url(
            GetProcAddrN('cef_create_url'));
        cef_get_mime_type := tfn_cef_get_mime_type(
            GetProcAddrN('cef_get_mime_type'));

        cef_urlrequest_create := tfn_cef_urlrequest_create(
            GetProcAddrN('cef_urlrequest_create'));

        cef_v8context_get_current_context := tfn_cef_v8context_get_current_context(
            GetProcAddrN('cef_v8context_get_current_context'));
        cef_v8context_get_entered_context := tfn_cef_v8context_get_entered_context(
            GetProcAddrN('cef_v8context_get_entered_context'));
        cef_v8context_in_context := tfn_cef_v8context_in_context(
            GetProcAddrN('cef_v8context_in_context'));
        cef_v8value_create_undefined := tfn_cef_v8value_create_undefined(
            GetProcAddrN('cef_v8value_create_undefined'));
        cef_v8value_create_null := tfn_cef_v8value_create_null(
            GetProcAddrN('cef_v8value_create_null'));
        cef_v8value_create_bool := tfn_cef_v8value_create_bool(
            GetProcAddrN('cef_v8value_create_bool'));
        cef_v8value_create_int := tfn_cef_v8value_create_int(
            GetProcAddrN('cef_v8value_create_int'));
        cef_v8value_create_uint := tfn_cef_v8value_create_uint(
            GetProcAddrN('cef_v8value_create_uint'));
        cef_v8value_create_double := tfn_cef_v8value_create_double(
            GetProcAddrN('cef_v8value_create_double'));
        cef_v8value_create_date := tfn_cef_v8value_create_date(
            GetProcAddrN('cef_v8value_create_date'));
        cef_v8value_create_string := tfn_cef_v8value_create_string(
            GetProcAddrN('cef_v8value_create_string'));
        cef_v8value_create_object := tfn_cef_v8value_create_object(
            GetProcAddrN('cef_v8value_create_object'));
        cef_v8value_create_array := tfn_cef_v8value_create_array(
            GetProcAddrN('cef_v8value_create_array'));
        cef_v8value_create_function := tfn_cef_v8value_create_function(
            GetProcAddrN('cef_v8value_create_function'));
        cef_v8stack_trace_get_current := tfn_cef_v8stack_trace_get_current(
            GetProcAddrN('cef_v8stack_trace_get_current'));
        cef_register_extension := tfn_cef_register_extension(
            GetProcAddrN('cef_register_extension'));

        cef_binary_value_create := tfn_cef_binary_value_create(
            GetProcAddrN('cef_binary_value_create'));
        cef_dictionary_value_create := tfn_cef_dictionary_value_create(
            GetProcAddrN('cef_dictionary_value_create'));
        cef_list_value_create := tfn_cef_list_value_create(
            GetProcAddrN('cef_list_value_create'));

        cef_visit_web_plugin_info := tfn_cef_visit_web_plugin_info(
            GetProcAddrN('cef_visit_web_plugin_info'));
        cef_refresh_web_plugins := tfn_cef_refresh_web_plugins(
            GetProcAddrN('cef_refresh_web_plugins'));
        cef_add_web_plugin_path := tfn_cef_add_web_plugin_path(
            GetProcAddrN('cef_add_web_plugin_path'));
        cef_add_web_plugin_directory := tfn_cef_add_web_plugin_directory(
            GetProcAddrN('cef_add_web_plugin_directory'));
        cef_remove_web_plugin_path := tfn_cef_remove_web_plugin_path(
            GetProcAddrN('cef_remove_web_plugin_path'));
        cef_unregister_internal_web_plugin := tfn_cef_unregister_internal_web_plugin(
            GetProcAddrN('cef_unregister_internal_web_plugin'));
        cef_force_web_plugin_shutdown := tfn_cef_force_web_plugin_shutdown(
            GetProcAddrN('cef_force_web_plugin_shutdown'));
        cef_register_web_plugin_crash := tfn_cef_register_web_plugin_crash(
            GetProcAddrN('cef_register_web_plugin_crash'));
        cef_is_web_plugin_unstable := tfn_cef_is_web_plugin_unstable(
            GetProcAddrN('cef_is_web_plugin_unstable'));

        cef_xml_reader_create := tfn_cef_xml_reader_create(
            GetProcAddrN('cef_xml_reader_create'));

        cef_zip_reader_create := tfn_cef_zip_reader_create(
            GetProcAddrN('cef_zip_reader_create'));

        cef_string_wide_set := tfn_cef_string_wide_set(
		    GetProcAddrN('cef_string_wide_set'));
        cef_string_utf8_set := tfn_cef_string_utf8_set(
		    GetProcAddrN('cef_string_utf8_set'));
        cef_string_utf16_set := tfn_cef_string_utf16_set(
		    GetProcAddrN('cef_string_utf16_set'));
        cef_string_wide_clear := tfn_cef_string_wide_clear(
		    GetProcAddrN('cef_string_wide_clear'));
        cef_string_utf8_clear := tfn_cef_string_utf8_clear(
		    GetProcAddrN('cef_string_utf8_clear'));
        cef_string_utf16_clear := tfn_cef_string_utf16_clear(
		    GetProcAddrN('cef_string_utf16_clear'));
        cef_string_wide_cmp := tfn_cef_string_wide_cmp(
		    GetProcAddrN('cef_string_wide_cmp'));
        cef_string_utf8_cmp := tfn_cef_string_utf8_cmp(
		    GetProcAddrN('cef_string_utf8_cmp'));
        cef_string_utf16_cmp := tfn_cef_string_utf16_cmp(
		    GetProcAddrN('cef_string_utf16_cmp'));
        cef_string_wide_to_utf8 := tfn_cef_string_wide_to_utf8(
		    GetProcAddrN('cef_string_wide_to_utf8'));
        cef_string_utf8_to_wide := tfn_cef_string_utf8_to_wide(
		    GetProcAddrN('cef_string_utf8_to_wide'));
        cef_string_wide_to_utf16 := tfn_cef_string_wide_to_utf16(
		    GetProcAddrN('cef_string_wide_to_utf16'));
        cef_string_utf16_to_wide := tfn_cef_string_utf16_to_wide(
		    GetProcAddrN('cef_string_utf16_to_wide'));
        cef_string_utf8_to_utf16 := tfn_cef_string_utf8_to_utf16(
		    GetProcAddrN('cef_string_utf8_to_utf16'));
        cef_string_utf16_to_utf8 := tfn_cef_string_utf16_to_utf8(
		    GetProcAddrN('cef_string_utf16_to_utf8'));
        cef_string_ascii_to_wide := tfn_cef_string_ascii_to_wide(
		    GetProcAddrN('cef_string_ascii_to_wide'));
        cef_string_ascii_to_utf16 := tfn_cef_string_ascii_to_utf16(
		    GetProcAddrN('cef_string_ascii_to_utf16'));
        cef_string_userfree_wide_alloc := tfn_cef_string_userfree_wide_alloc(
		    GetProcAddrN('cef_string_userfree_wide_alloc'));
        cef_string_userfree_utf8_alloc := tfn_cef_string_userfree_utf8_alloc(
		    GetProcAddrN('cef_string_userfree_utf8_alloc'));
        cef_string_userfree_utf16_alloc := tfn_cef_string_userfree_utf16_alloc(
		    GetProcAddrN('cef_string_userfree_utf16_alloc'));
        cef_string_userfree_wide_free := tfn_cef_string_userfree_wide_free(
		    GetProcAddrN('cef_string_userfree_wide_free'));
        cef_string_userfree_utf8_free := tfn_cef_string_userfree_utf8_free(
		    GetProcAddrN('cef_string_userfree_utf8_free'));
        cef_string_userfree_utf16_free := tfn_cef_string_userfree_utf16_free(
		    GetProcAddrN('cef_string_userfree_utf16_free'));

        cef_string_list_alloc := tfn_cef_string_list_alloc(
		    GetProcAddrN('cef_string_list_alloc'));
        cef_string_list_size := tfn_cef_string_list_size(
		    GetProcAddrN('cef_string_list_size'));
        cef_string_list_value := tfn_cef_string_list_value(
		    GetProcAddrN('cef_string_list_value'));
        cef_string_list_append := tfn_cef_string_list_append(
		    GetProcAddrN('cef_string_list_append'));
        cef_string_list_clear := tfn_cef_string_list_clear(
		    GetProcAddrN('cef_string_list_clear'));
        cef_string_list_free := tfn_cef_string_list_free(
		    GetProcAddrN('cef_string_list_free'));
        cef_string_list_copy := tfn_cef_string_list_copy(
		    GetProcAddrN('cef_string_list_copy'));

        cef_string_map_alloc := tfn_cef_string_map_alloc(
		    GetProcAddrN('cef_string_map_alloc'));
        cef_string_map_size := tfn_cef_string_map_size(
		    GetProcAddrN('cef_string_map_size'));
        cef_string_map_find := tfn_cef_string_map_find(
		    GetProcAddrN('cef_string_map_find'));
        cef_string_map_key := tfn_cef_string_map_key(
		    GetProcAddrN('cef_string_map_key'));
        cef_string_map_value := tfn_cef_string_map_value(
		    GetProcAddrN('cef_string_map_value'));
        cef_string_map_append := tfn_cef_string_map_append(
		    GetProcAddrN('cef_string_map_append'));
        cef_string_map_clear := tfn_cef_string_map_clear(
		    GetProcAddrN('cef_string_map_clear'));
        cef_string_map_free := tfn_cef_string_map_free(
		    GetProcAddrN('cef_string_map_free'));

        cef_string_multimap_alloc := tfn_cef_string_multimap_alloc(
		    GetProcAddrN('cef_string_multimap_alloc'));
        cef_string_multimap_size := tfn_cef_string_multimap_size(
		    GetProcAddrN('cef_string_multimap_size'));
        cef_string_multimap_find_count := tfn_cef_string_multimap_find_count(
		    GetProcAddrN('cef_string_multimap_find_count'));
        cef_string_multimap_enumerate := tfn_cef_string_multimap_enumerate(
		    GetProcAddrN('cef_string_multimap_enumerate'));
        cef_string_multimap_key := tfn_cef_string_multimap_key(
		    GetProcAddrN('cef_string_multimap_key'));
        cef_string_multimap_value := tfn_cef_string_multimap_value(
		    GetProcAddrN('cef_string_multimap_value'));
        cef_string_multimap_append := tfn_cef_string_multimap_append(
		    GetProcAddrN('cef_string_multimap_append'));
        cef_string_multimap_clear := tfn_cef_string_multimap_clear(
		    GetProcAddrN('cef_string_multimap_clear'));
        cef_string_multimap_free := tfn_cef_string_multimap_free(
		    GetProcAddrN('cef_string_multimap_free'));


        {$ifdef cef_trunk}
        //cef_print_settings_create := tfn_cef_print_settings_create(
        //    GetProcAddrN('cef_print_settings_create'));
        {$endif cef_trunk}

        {$IFDEF CEF_STRING_TYPE_UTF8}
        cef_string_set            := cef_string_utf8_set;
        cef_string_clear          := cef_string_utf8_clear;
        cef_string_userfree_alloc := cef_string_userfree_utf8_alloc;
        cef_string_userfree_free  := cef_string_userfree_utf8_free;
        cef_string_from_ascii     := cef_string_utf8_copy;
        cef_string_to_utf8        := cef_string_utf8_copy;
        cef_string_from_utf8      := cef_string_utf8_copy;
        cef_string_to_utf16       := cef_string_utf8_to_utf16;
        cef_string_from_utf16     := cef_string_utf16_to_utf8;
        cef_string_to_wide        := cef_string_utf8_to_wide;
        cef_string_from_wide      := cef_string_wide_to_utf8;
        {$ENDIF}

        {$IFDEF CEF_STRING_TYPE_UTF16}
        cef_string_set            := cef_string_utf16_set;
        cef_string_clear          := cef_string_utf16_clear;
        cef_string_userfree_alloc := cef_string_userfree_utf16_alloc;
        cef_string_userfree_free  := cef_string_userfree_utf16_free;
        cef_string_from_ascii     := cef_string_ascii_to_utf16;
        cef_string_to_utf8        := cef_string_utf16_to_utf8;
        cef_string_from_utf8      := cef_string_utf8_to_utf16;
        cef_string_to_utf16       := @cef_string_utf16_copy;
        cef_string_from_utf16     := @cef_string_utf16_copy;
        cef_string_to_wide        := cef_string_utf16_to_wide;
        cef_string_from_wide      := cef_string_wide_to_utf16;
        {$ENDIF}

        {$IFDEF CEF_STRING_TYPE_WIDE}
        cef_string_set            := cef_string_wide_set;
        cef_string_clear          := cef_string_wide_clear;
        cef_string_userfree_alloc := cef_string_userfree_wide_alloc;
        cef_string_userfree_free  := cef_string_userfree_wide_free;
        cef_string_from_ascii     := cef_string_ascii_to_wide;
        cef_string_to_utf8        := cef_string_wide_to_utf8;
        cef_string_from_utf8      := cef_string_utf8_to_wide;
        cef_string_to_utf16       := cef_string_wide_to_utf16;
        cef_string_from_utf16     := cef_string_utf16_to_wide;
        cef_string_to_wide        := cef_string_wide_copy;
        cef_string_from_wide      := cef_string_wide_copy;
        {$ENDIF}

        if fle <> '' then
            raise Exception.Create('Error loading library:' + fle);

        {$IFDEF DEBUG}
        Debugln('   : Loaded');
        {$ENDIF}
    end
    {$IFDEF DEBUG}
    else Debugln('   : already loaded')
    {$ENDIF}
    ;
end;

procedure CefCloseLibrary;
begin
    {$IFDEF DEBUG}
    Debugln('CefCloseLibrary');
    {$ENDIF}
    if LibHandle <> 0 then
    begin
        {$IFDEF DEBUG}
        Debugln('   : Freed');
        {$ENDIF}

        UnloadLibrary(LibHandle);
        LibHandle := 0;
    end
    {$IFDEF DEBUG}
    else
        Debugln('   : already freed.')
    {$ENDIF}
    ;
end;

finalization
    CefCloseLibrary;

end.
